<template>
    <div class="orderLog">
        <div style="height: 600px;">
            <Table :columns="tableColumns" :loading="loading" :data-source="tableData" style="margin-top: 20px;" />
        </div>

        <Pagination style="margin-left: auto;margin-top: 20px;" :key="pageSize + 'Pagination' + currentPage" :count="total"
            :page-size="pageSize" :pageNo="currentPage" @onPagechange="handlePageChange"
            @onSizechange="handleSizeChange" />
    </div>
</template>
<script setup lang="ts">
    import {getOrderLogList} from '@/api/purchase'
    import type { TableProps, TableColumn } from '@/types/table';
    import stores from '@/store';
    import type { OrderLogResponse,OrderLogResponseData,OrderLogResponseDataList } from '@/types/purchase'
    const loading = ref<boolean>(false)
    const tableData = ref<OrderLogResponseDataList[]>([])
    const currentPage = ref(1);
    const pageSize = ref(10);
    const total = ref(0);
    const tableColumns: TableColumn[] = [
        { prop: 'createTime', label: '业务时间' },
        { prop: 'createBy', label: '操作人' },
        { prop: 'logType', label: '业务类型' },
        { prop: 'remark', label: '备注' },
    ]
    
    const handlePageChange = (page: number) => {
        currentPage.value = page;
        getOrderLogListApi()
    };
    const handleSizeChange = (size: number) => {
        currentPage.value = 1;
        pageSize.value = size;
        getOrderLogListApi()

    };
    const dataType = defineProps<{ orderId:any,  }>();
    const purchaseOrderStatusEnum =  ref<any>(stores.useBaseDataStore().getEnumSelect('stockLogTypeEnum'))

    const getOrderLogListApi = async()=>{
        let data = {
            orderId:dataType.orderId,
            orderType:1,
            pageNo:currentPage.value,
            pageSize:pageSize.value
        }
        let res = await getOrderLogList(data)
         if(res.code != '200'){
            //ElMessage.error(res.msg);
            return
        }
        total.value = res.data.totalCount
        res.data.list.forEach(item=>{
             for (let index = 0; index < purchaseOrderStatusEnum.value.length; index++) {
                let items = purchaseOrderStatusEnum.value[index];
                if(item.logType  == items.value){
                    item.logType  = items.text
                }
            }
            
        })
        tableData.value = res.data.list
    }
    getOrderLogListApi()
</script>

<style lang="scss">
    .orderLog{
        position: relative;
        height: 670px;
        .table-pagination{
            width: 100% !important;
        }
    }
</style>